<!DOCTYPE html>
<html lang="zh-cmn-Hans" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<link rel="shortcut icon" href="favicon.ico">
	<link rel="stylesheet" href="css/iconfont.css">
	<link rel="stylesheet" href="css/global.css">
	<link rel="stylesheet" href="css/bootstrap.min.css">
	<link rel="stylesheet" href="css/bootstrap-theme.min.css">
	<link rel="stylesheet" href="css/swiper.min.css">
	<link rel="stylesheet" href="css/styles.css">
	<script src="js/jquery.1.12.4.min.js" charset="UTF-8"></script>
	<script src="js/bootstrap.min.js" charset="UTF-8"></script>
	<script src="js/swiper.min.js" charset="UTF-8"></script>
	<script src="js/global.js" charset="UTF-8"></script>
	<script src="js/jquery.DJMask.2.1.1.js" charset="UTF-8"></script>
	<title>农资商贸销售系统</title>
</head>
<body>
<!-- 顶部tab -->
<div th:replace="~{mall/common :: header}"></div>

<!-- 顶部标题 -->
<div class="bgf5 clearfix">
	<div class="top-user">
		<div class="inner">
			<a style="left: -22px;top: 15px;width: 246px;height: 188px;" class="logo" href="index"><img src="images/icons/logo.png" alt="农资商贸销售系统" class="cover"></a>
			<div class="title">个人中心</div>
		</div>
	</div>
</div>
<div class="content clearfix bgf5">
	<section class="user-center inner clearfix">
		<div class="pull-left bgf">
			<a href="index"><span class="title">农资商城销售系统</span></a>
			<dl class="user-center__nav">
				<dt>帐户信息</dt>
				<a href="userSetting">
					<dd>个人资料</dd>
				</a>
				<a href="userAddress">
					<dd class="active">收货地址</dd>
				</a>
				<a href="userUpdatePwd">
					<dd>修改登录密码</dd>
				</a>
			</dl>
			<dl class="user-center__nav">
				<dt>订单中心</dt>
				<a href="userOrder">
					<dd>我的订单</dd>
				</a>
			</dl>
		</div>
		<div class="pull-right">
			<div class="user-content__box clearfix bgf">
				<div class="title">账户信息-编辑收货地址</div>
				<form class="user-addr__form form-horizontal" role="form">
					<p class="fz18 cr">编辑收货地址</p>
					<div class="form-group" style="display: none;">
						<label for="id" class="col-sm-2 control-label">ID：</label>
						<div class="col-sm-6">
							<input class="form-control" th:value="${useradress.id}" id="id" name="id" placeholder="请输入姓名" type="text">
						</div>
					</div>
					<div class="form-group">
						<label for="shname" class="col-sm-2 control-label">收货人姓名：</label>
						<div class="col-sm-6">
							<input class="form-control" th:value="${useradress.shname}" id="shname" name="shname" placeholder="请输入姓名" type="text">
						</div>
					</div>
					<div class="form-group">
						<label for="shprovince" class="col-sm-2 control-label">省份：</label>
						<div class="col-sm-6">
							<input class="form-control" th:value="${useradress.shprovince}" id="shprovince" name="shprovince" placeholder="请输入省份" maxlength="30" type="text">
						</div>
					</div>
					<div class="form-group">
						<label for="shcity" class="col-sm-2 control-label">市区：</label>
						<div class="col-sm-6">
							<input class="form-control" th:value="${useradress.shcity}" id="shcity" name="shcity" placeholder="请输入市区" maxlength="30" type="text">
						</div>
					</div>
					<div class="form-group">
						<label for="district" class="col-sm-2 control-label">区/县：</label>
						<div class="col-sm-6">
							<input class="form-control" th:value="${useradress.district}" id="district" name="district" placeholder="请输入区/县" maxlength="30" type="text">
						</div>
					</div>
					<div class="form-group">
						<label for="shstreet" class="col-sm-2 control-label">街道：</label>
						<div class="col-sm-6">
							<input class="form-control" th:value="${useradress.shstreet}" id="shstreet" name="shstreet" placeholder="请输入街道" maxlength="30" type="text">
						</div>
					</div>
					<div class="form-group">
						<label for="shjaddress" class="col-sm-2 control-label">详细地址：</label>
						<div class="col-sm-10">
							<input class="form-control" th:value="${useradress.shjaddress}" id="shjaddress" name="shjaddress" placeholder="建议您如实填写详细收货地址，例如街道名称，门牌号码等信息" maxlength="30" type="text">
						</div>
					</div>
					<div class="form-group">
						<label for="shphone" class="col-sm-2 control-label">手机号码：</label>
						<div class="col-sm-6">
							<input class="form-control" th:value="${useradress.shphone}" id="shphone" name="shphone" placeholder="请输入手机号码" type="text">
						</div>
					</div>
					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-6">
							<div class="checkbox">
								<label><input name="isDefault" type="checkbox" value="1" th:checked="${useradress.dedaultadress==1}"><i></i> 设为默认收货地址</label>
							</div>
						</div>
					</div>
					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-6">
							<button type="button" class="but" onclick="submitAdress()">保存</button>
						</div>
					</div>
				</form>
				<script>
					function submitAdress() {
						//获取各个参数
						let id = $("#id").val();
						let shname = $("#shname").val();
						let shprovince = $("#shprovince").val();
						let shcity = $("#shcity").val();
						let district = $("#district").val();
						let shstreet = $("#shstreet").val();
						let shjaddress = $("#shjaddress").val();
						let shphone = $("#shphone").val();
						//获取是否选中了默认地址
						let isDefaultAddress = $("input[name='isDefault']").prop('checked');
						if (!id || !shname || !shprovince || !shcity || !shstreet || !shjaddress || !shphone || !district){
							DJMask.open({
								width: "300px",
								height: "100px",
								content: "请填写完整信息"
							})
							return false;
						}
						let dedaultadress=isDefaultAddress?1:2;
						$.ajax({
							url: "/mall/useradress/update",
							type: "post",
							data: {id,shname, shprovince, shcity, district, shstreet, shjaddress, shphone,dedaultadress},
							success: function (res) {
								if (res.code === 200) {
									DJMask.open({
										width: "300px",
										height: "100px",
										content: res.msg
									})
									//倒计时一秒刷新当前页面
									setTimeout(function () {
										self.location = document.referrer;
									}, 1000);
								} else  if (res.code === 401){
									DJMask.open({
										width: "300px",
										height: "100px",
										content: res.msg+"，将在三秒后自动跳转到登录页面"
									})
									//倒计时三秒跳转到登录页面
									setTimeout(function () {
										window.location.href="/mall/login";
									}, 3000);
								}else{
									DJMask.open({
										width: "300px",
										height: "100px",
										content: res.msg
									})
								}
							},
							error: function (res) {
								DJMask.open({
									width: "300px",
									height: "100px",
									content: "网络繁忙，请稍后再试！！！"
								})
							}
						})
					}
				</script>
			</div>
		</div>
	</section>
</div>

<!-- 右侧菜单 -->
<div th:replace="~{mall/common :: rightNav}"></div>
<!-- 底部信息 -->
<div th:replace="~{mall/common :: footer}"></div>
<link href="css/cropper/cropper.min.css" rel="stylesheet">
<link href="css/cropper/sitelogo.css" rel="stylesheet">
<script src="js/cropper/cropper.min.js"></script>
<script src="js/cropper/sitelogo.js"></script>


</body>
</html>